package com.handinglian.ai.system.controller;

import com.apidoc.annotation.Api;
import com.handinglian.ai.common.dto.ResultData;
import com.handinglian.ai.system.dto.LoginDto;
import com.handinglian.ai.system.service.LoginService;
import com.handinglian.ai.system.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api("登录")
@RestController
@Slf4j
public class LoginController {
    @Autowired
    private LoginService loginService;
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 登录失败或已经登录，真正登录的POST请求由Filter完成(common)
     */
    @PostMapping("/login")
    public ResultData login(HttpServletRequest request, HttpServletResponse response, @RequestBody(required = false) LoginDto loginDto){
        return loginService.login(request, response);
    }

    /**
     * 退出，实际逻辑在LogoutFilter中实现
     */
    @GetMapping("/logout")
    public ResultData logout(){
        return ResultData.logout();
    }

    /**
     * 获取jessionid
     */
    @GetMapping("/getJSessionId")
    public ResultData getJSessionId(HttpServletRequest request){
        return loginService.getJSessionId(request);
    }

}
